// MongoDB 初始化脚本

// 创建数据库
db = db.getSiblingDB('lesson-plan');

// 创建用户
db.createUser({
  user: 'app_user',
  pwd: 'app_password',
  roles: [
    {
      role: 'readWrite',
      db: 'lesson-plan'
    }
  ]
});

// 初始化分类数据
db.categories.insertMany([
  // 学科分类
  { name: '数学', type: 'subject', order: 1, isActive: true },
  { name: '语文', type: 'subject', order: 2, isActive: true },
  { name: '英语', type: 'subject', order: 3, isActive: true },
  { name: '科学', type: 'subject', order: 4, isActive: true },
  { name: '历史', type: 'subject', order: 5, isActive: true },
  { name: '地理', type: 'subject', order: 6, isActive: true },
  { name: '物理', type: 'subject', order: 7, isActive: true },
  { name: '化学', type: 'subject', order: 8, isActive: true },
  { name: '生物', type: 'subject', order: 9, isActive: true },
  { name: '音乐', type: 'subject', order: 10, isActive: true },
  { name: '美术', type: 'subject', order: 11, isActive: true },
  { name: '体育', type: 'subject', order: 12, isActive: true },
  
  // 年级分类
  { name: '一年级', type: 'grade', order: 1, isActive: true },
  { name: '二年级', type: 'grade', order: 2, isActive: true },
  { name: '三年级', type: 'grade', order: 3, isActive: true },
  { name: '四年级', type: 'grade', order: 4, isActive: true },
  { name: '五年级', type: 'grade', order: 5, isActive: true },
  { name: '六年级', type: 'grade', order: 6, isActive: true },
  { name: '七年级', type: 'grade', order: 7, isActive: true },
  { name: '八年级', type: 'grade', order: 8, isActive: true },
  { name: '九年级', type: 'grade', order: 9, isActive: true },
  { name: '高一', type: 'grade', order: 10, isActive: true },
  { name: '高二', type: 'grade', order: 11, isActive: true },
  { name: '高三', type: 'grade', order: 12, isActive: true },
  
  // 课程类型
  { name: '新授课', type: 'courseType', order: 1, isActive: true },
  { name: '复习课', type: 'courseType', order: 2, isActive: true },
  { name: '练习课', type: 'courseType', order: 3, isActive: true },
  { name: '实验课', type: 'courseType', order: 4, isActive: true },
  { name: '活动课', type: 'courseType', order: 5, isActive: true },
  { name: '讲评课', type: 'courseType', order: 6, isActive: true }
]);

// 创建默认管理员用户
db.users.insertOne({
  email: 'admin@example.com',
  // 密码: admin123 (需要在应用中使用 bcrypt 加密)
  password: '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
  name: '系统管理员',
  role: 'admin',
  avatar: '',
  bio: '系统管理员账号',
  createdAt: new Date(),
  updatedAt: new Date()
});

print('数据库初始化完成！');
print('管理员账号: admin@example.com');
print('管理员密码: admin123');